import json

from flask import Blueprint, request
from flask_restful import Resource, Api

# 新增功能
import DcUrls

StartImage = Blueprint('startImage', __name__)
api = Api(StartImage)


class startImage(Resource):
    def get(self):
        # reqJson = json.loads(request.data)
        # print(reqJson)
        images = []
        images.append("https://img0.baidu.com/it/u=1110157243,2891229005&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img0.baidu.com/it/u=1088473955,1845127087&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img2.baidu.com/it/u=1156205808,345646853&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img2.baidu.com/it/u=774630389,4183528837&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img0.baidu.com/it/u=1570602913,157918019&fm=26&fmt=auto&gp=0.jpg")
        img = {"images": images}
        res = setResult(img)
        return res

    def post(self):
        reqJson = json.loads(request.data)
        print(reqJson)
        images = []
        images.append("https://img0.baidu.com/it/u=1110157243,2891229005&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img0.baidu.com/it/u=1088473955,1845127087&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img2.baidu.com/it/u=1156205808,345646853&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img2.baidu.com/it/u=774630389,4183528837&fm=26&fmt=auto&gp=0.jpg")
        images.append("https://img0.baidu.com/it/u=1570602913,157918019&fm=26&fmt=auto&gp=0.jpg")
        img = {"images": images}
        res = setResult(img)
        return res


api.add_resource(startImage, '/getStartImages')


def setResult(data):
    """
    通用返回数据格式
    :param data: 详细数据
    :return: result
    """
    result = {"code": 200, "message": "获取成功", "data": data}
    return result
